﻿namespace CloudNinja.Metering.Web.Controllers
{
    using System.Linq;
    using System.Threading.Tasks;
    using System.Web.Http;
    using System.Web.Http.OData;

    using CloudNinja.Metering.Data;
    using CloudNinja.Metering.Data.Models;

    public class MeterDataController : ODataController
    {
        private readonly IMeteringReporting meteringReporting;

        public MeterDataController(IMeteringReporting meteringReporting)
        {
            this.meteringReporting = meteringReporting;
        }

        [Queryable]
        public async Task<IQueryable<MeterData>> Get()
        {
            // Warning: this is a costly operation, and normally should be avoided. 
            // we are providing it here to preserve the completeness of the example.
            var result = await this.meteringReporting.GetMeterDataAsync();
            return result.AsQueryable();
        }
    }
}
